package j2metris;

/**
 * Represents a single position in space with an x- and a y-position.
 *
 * This class uses a coordinate system identical to that used by the standard
 * Java graphics libraries: the "origin" is the top-left corner. From that point,
 * proceeding to the right increases the x-value, and proceeding downward
 * increases the y-value.
 */
public class Coordinate
{
    protected final int y;
    protected final int x;

    public Coordinate(final int xPos, final int yPos)
    {
        x = xPos;
        y = yPos;
    }

    public Coordinate(Coordinate original)
    {
        y = original.y;
        x = original.x;
    }

    public Coordinate()
    {
        x = 0;
        y = 0;
    }

    public int getX()
    {
        return x;
    }

    public int getY()
    {
        return y;
    }

    public String toString()
    {
        return "(" + x + ", " + y + ")";
    }

    public Coordinate add(Coordinate c)
    {
        return new Coordinate(x + c.x, y + c.y);
    }
    
    public Coordinate multiply(int i)
    {
        return new Coordinate(x * i, y * i);
    }

    public Coordinate add(Direction.TranslationDirection d, int value)
    {
        return add(d.getCoordinate().multiply(value));
    }

    public boolean isHigherThan(Coordinate c)
    {
        return y < c.y;
    }

    public boolean isHigherThan(int i)
    {
        return y < i;
    }

    public boolean isLowerThan(Coordinate c)
    {
        return y > c.y;
    }

    public boolean isLowerThan(int i)
    {
        return y > i;
    }

    public boolean isFurtherLeftThan(Coordinate c)
    {
        return x < c.x;
    }

    public boolean isFurtherLeftThan(int i)
    {
        return x < i;
    }

    public boolean isFurtherRightThan(Coordinate c)
    {
        return x > c.x;
    }

    public boolean isFurtherRightThan(int i)
    {
        return x > i;
    }

    public boolean isFurtherThan(Direction.TranslationDirection d, Coordinate c)
    {
        if(d == Direction.DOWN) return isLowerThan(c);
        if(d == Direction.LEFT) return isFurtherLeftThan(c);
        if(d == Direction.RIGHT) return isFurtherRightThan(c);
        else return isHigherThan(c);
    }

    public boolean isFurtherThan(Direction.TranslationDirection d, int i)
    {
        if(d == Direction.DOWN) return isLowerThan(i);
        if(d == Direction.LEFT) return isFurtherLeftThan(i);
        if(d == Direction.RIGHT) return isFurtherRightThan(i);
        else return isHigherThan(i);
    }

    public boolean equals(Coordinate c)
    {
        return x == c.x && y == c.y;
    }
}
